<template>
  <el-container class="home-container">
    <el-header>
      <div>
        <img src="../assets/aaa-logo.png" />
        <span>至善科技仓库管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse? '64px' : '200px'">
        <div class="toggle" @click="toggleCollage">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="istransition"
          :router="true"
          :default-active="activePath"
        >
          <el-submenu :index="menu.menuId+''" v-for="menu in leftMenu" :key="menu.menuId">
            <template slot="title">
              <i :class="menu.icon"></i>
              <span>{{menu.name}}</span>
            </template>
              <el-menu-item @click="submenuClick(submenu.url)" class="el-icon-menu" :index="submenu.url" :key="submenu.menuId" v-for="submenu in menu.children">{{submenu.name}}</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
          <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data(){
      return {
          leftMenu:[],
          isCollapse:false,
          istransition:false,
          activePath:'',
      }
  },
  created:function(){
      this.loadLeftMenu();
      this.activePath=window.sessionStorage.getItem("activePath");
  },
  methods: {
    logout: function () {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async loadLeftMenu(){
       let result= await this.$http.get("/system/menu/queryMenuTreeByUserId");
       if(result.data.code!==20000) return this.$message.error("菜单加载失败");
       this.leftMenu=result.data.data.menuTree;
    },
    toggleCollage(){
        this.isCollapse=!this.isCollapse
    },
    submenuClick(activePath){
        window.sessionStorage.setItem("activePath",activePath);
        this.activePath=activePath;
    }
  },
};
</script>
<style scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0px;
  align-items: center;
  color: #fff;
  font-size: 20px;
}
.el-header > div {
  display: flex;
  align-items: center;
}
.el-header > div > span {
  margin-left: 15px;
}
.el-aside {
  background-color: #333744;
  
}
.el-aside .el-menu{
      border:none;
  }
.el-main {
  background-color: #eaedf1;
}
.toggle{
    background-color: #4A5064;
    color: #fff;
    line-height: 24px;
    font-size: 10px;
    text-align: center;
    letter-spacing: 5px;
    cursor: pointer;
}
</style>